﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using Core.Message.Entities;
using Core.ExceptionHandling;
using Core.Controls.Message;
using vHCS.LS.Business;
using vHCS.RE.Business;
using System.Data;
using vHCS.HR.Entities;
using vHCS.HR.Business;
using Aspose.Words;
using Core.Common.Session;
using System.Configuration;
using vHCS.SYS.Business;
using vHCS.SYS.Entities;
using System.Globalization;

namespace vHCS.K2App.MdlK2.ResourceRequest.Ver1
{
    public partial class RE_RequestDetail : Core.NTier.UserInterface.BaseFormNotPer
    {
        #region Property
        protected string trvProChartClientId
        {
            get
            {
                try
                {
                    if (cboProChart.Items.Count > 0)
                    {
                        System.Web.UI.Control ctrlProchart = this.cboProChart.Items[0].FindControl("trvProChart");
                        return ctrlProchart.ClientID;
                    }

                }
                catch (Exception ex)
                {
                    AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                    MessageBox.Show(message);
                }
                return string.Empty;
            }
        }

        protected string trvMgtChartClientId
        {
            get
            {
                try
                {
                    if (cboMgtChart.Items.Count > 0)
                    {
                        System.Web.UI.Control ctrlMgtchart = this.cboMgtChart.Items[0].FindControl("trvMgtChart");
                        return ctrlMgtchart.ClientID;
                    }
                }
                catch (Exception ex)
                {
                    AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                    MessageBox.Show(message);
                }
                return string.Empty;
            }
        }
        #endregion
        private const string _REQUEST_DETAIL = "RE_RequestDetail.aspx";
        private const string _REQUESTLIST = "~/MdlRE/RE_RequestList.aspx";
        private const string _MATCHSENDCV = "~/MdlRE/RE_MatchSendCV.aspx?RequestID={0}";
        private const string _POSTJOB = "~/MdlRE/RE_PostJobList.aspx?RequestID={0}";
        private const string _TASK = "~/MdlRE/RE_ManageTask.aspx?RequestID={0}";
        private const string _FileName_Request = "HR-RR-FM-ResourceRequest-EN.doc";

        #region Event
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    
                    loadGeneralInfo(SessionManager.UserDomain, true);
                    ClientScript.RegisterStartupScript(Page.GetType(), "LoadMaximize", "LoadMaximize();", true);
                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }
        protected void cboNguoiYeuCau_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                this.refreshControl(true);
                loadGeneralInfo(cboNguoiYeuCau.SelectedValue, false);
                //LoadFormForJobTitle();
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        protected void cboDepartment_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(cboDepartment.SelectedValue))
                {
                    K2Collection k2col=new K2Collection();
                    HR.Business.HIE_HierarchyCollection hie_col = new HR.Business.HIE_HierarchyCollection();
                    HR.Business.HIE_HierarchyBL hie_bl = new HR.Business.HIE_HierarchyBL();

                    txtIDPhongBan.Text = cboDepartment.SelectedValue;
                    txtIDBoPhan.Text = k2col.GetHierarchyIdByLevel(Convert.ToInt64(txtIDPhongBan.Text), 2).ToString().Trim();

                    //get name dept
                    hie_bl = hie_col.SelectByID(Convert.ToInt64(txtIDPhongBan.Text.Trim()));
                    if (hie_bl.DTO != null)
                    {
                        hdfPhongBanName.Value = hie_bl.NameEN;
                    }

                    //get name div
                    hie_bl = hie_col.SelectByID(Convert.ToInt64(txtIDBoPhan.Text.Trim()));
                    if (hie_bl.DTO != null)
                        hdfBoPhanName.Value = hie_bl.NameEN;

                    
                }

            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        protected void cboChucvu_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.refreshControl(true);
            try
            {
                long jobtitle = 0;
                long.TryParse(cboChucvu.SelectedValue, out jobtitle);

                if (jobtitle > 0)
                {
                    PopulateJobTitle(jobtitle);
                }
                else lblCanhBaoProChart.Visible = false;
                cboPCApply.DataBind();
                cboPCStandard.DataBind();

                SetComboPC();
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
            //LoadFormForJobTitle();
        }

        protected void cboCapbac_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            try
            {
                cboPCApply.DataBind();
                cboPCStandard.DataBind();

                SetComboPC();
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        protected void btnThemMoi_Top_Click(object sender, EventArgs e)
        {
            Response.Redirect(_REQUEST_DETAIL);
            loadGeneralInfo(SessionManager.Username, true); // Load lại thông tin chung           
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="isRefreshMoTa"></param>: true có refresh cboMoTa, false: ko refresh cboMota
        protected void refreshControl(bool isRefreshMoTa)
        {

            txtGhiChuClose.InnerText = "";
            //Refresh các control
            if (isRefreshMoTa)
            {
                cboMoTa.DataBind();
                cboMoTa.SelectedValue = null;
                cboMoTa.Text = "";
            }
            cboLanguageSkill.DataBind();
            cboProSkill.DataBind();
            cboSoftSkill.DataBind();

            cboTrinhDoHocVan.DataBind();
            cboTrinhDoHocVan.SelectedValue = null;
            cboTrinhDoHocVan.Text = "";

            txtTenJob.Text = "";
            cboProChart.Items.Clear();
            cboProChart.Items.Insert(0, new RadComboBoxItem("", ""));
            cboProChart.SelectedIndex = 0;
            cboMgtChart.Items.Clear();
            cboMgtChart.Items.Insert(0, new RadComboBoxItem("", ""));
            cboMgtChart.SelectedIndex = 0;

            chkSuDung.Checked = false;
            txtMoTaTiengViet.Content = "";
            txtMoTaTiengAnh.Content = "";
            txtYeuCauTiengViet.Content = "";
            txtYeuCauTiengAnh.Content = "";
            txtUuTienTiengViet.Content = "";
            txtUuTienTiengAnh.Content = "";

            //rdlLyDoTuyen.SelectedValue = "1";
            //cboReplaceFor.DataBind();
            //cboReportTo.DataBind();
            //cboVanphonglamviec.DataBind();
            //txtSoLuongTuyen.Text = "";        
            //rdlGender.SelectedValue = "3";
            //rdlJobType.SelectedValue = "1";
            //cboReportTo.SelectedValue = null;
            //cboReportTo.Text = "";
        }
        protected void btnSave_Top_Click(object sender, EventArgs e)
        {
            string reqID = "";
            try
            {
                //loadGeneralInfo(txtRequester.Text, false);
                RE_RequestCollection collection = new RE_RequestCollection();
                RE_RequestBL blRequest = addDataToObject();
                // Lưu với trạng thái Saved                

                if (hdfStatusRequest.Value == "5")// Neu o trang thai reject--> save lai voi trang thai Saved
                    blRequest.Status = 1;
                if (hdfStatusRequest.Value != "")
                    blRequest.Status = Int16.Parse(hdfStatusRequest.Value);
                string messCode = "";
                messCode = collection.Save_K2(blRequest, out reqID);
                if (reqID != "")
                {
                    this.hdfRequestID.Value = reqID;
                }

                ExcuteK2Process(reqID);
                ClientScript.RegisterStartupScript(Page.GetType(), "ClosePage", "ClosePage();", true);

                btnSave_Top.Enabled = true;
                btnSave_Bot.Enabled = true;
            }
            catch (Exception ex)
            {
                AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(mess);
            }

        }


        //protected void btnSubmit_Top_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        RE_RequestCollection collection = new RE_RequestCollection();
        //        RE_RequestBL blRequest = addDataToObject();
        //        // Lưu với trạng thái Waiting (chờ phê duyệt)
        //        blRequest.Status = 2;
        //        string messCode = "";
        //        messCode = collection.Save(blRequest);
        //        MessageBox.ShowByMessCode(messCode);
        //    }
        //    catch (Exception ex)
        //    {
        //        AlertMessage mess = UserInterfaceExceptionHandler.HandleExcetion(ex);
        //        MessageBox.Show(mess);
        //    }

        //}
        // Export ra request Form
        protected void btnExport_Top_Click(object sender, EventArgs e)
        {
            RE_RequestCollection jDes = new RE_RequestCollection();
            DataTable dt = jDes.GetForRequestForm(this.hdfRequestID.Value);
            string filePath = "";
            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    dt.Rows[0]["JobDescriptionVN"] = txtMoTaTiengViet.Text;
                    dt.Rows[0]["JobDescriptionEN"] = txtMoTaTiengAnh.Text;
                    dt.Rows[0]["RequirementsVN"] = txtYeuCauTiengViet.Text;
                    dt.Rows[0]["RequirementsEN"] = txtYeuCauTiengAnh.Text;
                    dt.Rows[0]["PreferableVN"] = txtUuTienTiengViet.Text;
                    dt.Rows[0]["PreferableEN"] = txtUuTienTiengAnh.Text;
                    filePath = this.Server.MapPath(HR_ConfigManager.TemplateReportRE + _FileName_Request);
                    Aspose.Words.Document doc = new Aspose.Words.Document(filePath);
                    DocumentBuilder builder = new DocumentBuilder(doc);
                    doc.MailMerge.Execute(dt);
                    doc.Save(_FileName_Request, SaveFormat.Doc, SaveType.OpenInWord, Response);
                }
            }

        }
        protected void btnList_Top_Click(object sender, EventArgs e)
        {
            Response.Redirect(_REQUESTLIST);
        }
        protected void cboMoTa_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            this.refreshControl(false);
            LoadJobDescriptionByID(e.Value);
        }
        #endregion

        #region Function

        public void ExcuteK2Process(string ID)
        {
            try
            {
                K2Collection k2_col=new K2Collection();
                RE_RequestCollection col_re = new RE_RequestCollection();
                SYS_MailTemplateCollection mail_cl = new SYS_MailTemplateCollection();
                SYS_MailTemplateDTO mail_dto = new SYS_MailTemplateDTO();
                string HRBP = k2_col.GetUserOfHRP_Hierarchy(Convert.ToInt64(txtIDPhongBan.Text.Trim()));
                string assistantHRBP=k2_col.GetUserOfAssistantHRP_Hierarchy(Convert.ToInt64(txtIDPhongBan.Text.Trim()));

                #region Lấy thông tin gửi mail cho HRBP
                string MailSubject_HRBP = "";
                string MailContent_HRBP = "";
                string MailHRBP = "";
                string Position="";
                string MailRRM = "";
                string MailGroupRRM = "";

                //Lấy chức vụ yêu cầu tuyển dụng
                vHCS.LS.Business.LS_JobTitleCollection cl_jobtitle=new LS.Business.LS_JobTitleCollection();
                vHCS.LS.Business.LS_JobTitleBL bl_jobtitle=new LS.Business.LS_JobTitleBL();
                bl_jobtitle=cl_jobtitle.SelectByID(Convert.ToInt64(cboChucvu.SelectedValue));
                if(bl_jobtitle.DTO!=null)
                {
                    Position=bl_jobtitle.NameEN;
                }
                //
                
                //Gán các tham số cho mail
                mail_dto = mail_cl.GetMailContentWithSignature("RE_K2_SendMailHRP", "K2-Signature");
                MailContent_HRBP = mail_dto.ContentVN;
                MailContent_HRBP = MailContent_HRBP.Replace("$JobTitle$", Position);
                MailContent_HRBP = MailContent_HRBP.Replace("$Number$", txtSoLuongTuyen.Value.ToString());
                MailContent_HRBP = MailContent_HRBP.Replace("$Div/Dept$", cboDepartment.Text + "/" + hdfBoPhanName.Value);
                MailContent_HRBP = MailContent_HRBP.Replace("$Requestor$", SessionManager.UserDomain);
                MailContent_HRBP = MailContent_HRBP.Replace("$url$", ConfigurationManager.AppSettings.Get("RecruitmentApprove"));
                MailContent_HRBP = MailContent_HRBP.Replace("$HRBP$", assistantHRBP);

                MailSubject_HRBP = mail_dto.TitleVN;
                MailSubject_HRBP = MailSubject_HRBP.Replace("$JobTitle$", Position);
                MailSubject_HRBP = MailSubject_HRBP.Replace("$Requestor$",SessionManager.UserDomain);
                MailSubject_HRBP = MailSubject_HRBP.Replace("$Dept$", cboDepartment.Text);

                MailHRBP = (mail_cl.ReturnEmail(HRBP)+";"+mail_cl.ReturnEmail(assistantHRBP)).Trim(';');
                MailRRM = mail_cl.ReturnEmail(k2_col.GetUserRRM());
                //Điều kiện bổ sung gửi mail thêm cho NguyenVH
                DataTable dat1 = k2_col.GetValueK2ByCode("CCMAILRRM");
                foreach (DataRow row in dat1.Rows)
                {
                    MailGroupRRM += ";" + row["value"].ToString();
                }
                //
                //
                #endregion

                #region Lấy thông tin gửi mail cho Requestor
                mail_dto = mail_cl.GetMailContentWithSignature("RE_K2_SendMailRequestor", "K2-Signature");
                string MailSubject_Requestor = "";
                string MailContent_Requestor = "";

                //Gán các tham số cho mail
                MailContent_Requestor = mail_dto.ContentVN;
                MailContent_Requestor = MailContent_Requestor.Replace("$JobTitle$", Position);
                MailContent_Requestor = MailContent_Requestor.Replace("$JobFamily$", hdfJobFamily.Value);
                MailContent_Requestor = MailContent_Requestor.Replace("$JobGroup$", hdfJobGroup.Value);
                MailContent_Requestor = MailContent_Requestor.Replace("$Division$", txtBoPhan.Text);
                MailContent_Requestor = MailContent_Requestor.Replace("$Department$", txtPhongBan.Text);
                MailContent_Requestor = MailContent_Requestor.Replace("$Requestor$", SessionManager.UserDomain);
                MailContent_Requestor = MailContent_Requestor.Replace("$Date$", Convert.ToDateTime(dtpRequestDate.SelectedDate).ToShortDateString());
                MailContent_Requestor = MailContent_Requestor.Replace("$Reason$", rdlLyDoTuyen.SelectedValue == "1" ? "New" : (rdlLyDoTuyen.SelectedValue == "2" ? "Replace" : "Staff Movement"));
                MailContent_Requestor = MailContent_Requestor.Replace("$Requestby$", SessionManager.UserDomain);
                MailContent_Requestor = MailContent_Requestor.Replace("$Requestfor$", txtRequester.Text.Trim());
                MailContent_Requestor = MailContent_Requestor.Replace("$url$", ConfigurationManager.AppSettings.Get("History_RERequest") + ID);

                MailSubject_Requestor = mail_dto.TitleVN;
                MailSubject_Requestor = MailSubject_Requestor.Replace("$JobTitle$", Position);
                MailSubject_Requestor = MailSubject_Requestor.Replace("$Requestor$", SessionManager.UserDomain);
                MailSubject_Requestor = MailSubject_Requestor.Replace("$Dept$", txtPhongBan.Text.Trim());
                MailSubject_Requestor = MailSubject_Requestor.Replace("$Requestfor$", txtRequester.Text.Trim());
                string MailRequester = mail_cl.ReturnEmail(SessionManager.UserDomain);
                string MailRequestFor = mail_cl.ReturnEmail(txtRequester.Text.Trim());
                //
                #endregion

                
                int iTypeID = K2CoreLib.K2Utils.GetTypeIDProcessFromEfrom("HR_Recruitment");
                string sLinkContent = ConfigurationManager.AppSettings.Get("History_RERequest")+ID;
                string status = "0"; //(0: In process, 1: Complete, 2: Rework, 3:Reject)
                string eformid = K2CoreLib.K2Utils.submit2EForm(SessionManager.UserDomain, SessionManager.UserDomain, iTypeID, DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), sLinkContent, status,hdfRequestFor.Value);
                //Get version process
                string version = ConfigurationManager.AppSettings.Get("RR_CurrentVersion");
                //Get Expire 
                string ExpireDay = ConfigurationManager.AppSettings.Get("RR_ExpireDay");
                string ExpireAlert = ConfigurationManager.AppSettings.Get("RR_ExpireAlert");
                string ApproveLink = ConfigurationManager.AppSettings.Get("RecruitmentApprove") + "&RequestID=" + hdfRequestID.Value + "&RoleNext=$role$";
                string ViewHistoryLink = ConfigurationManager.AppSettings.Get("History_RERequest") + ID;

                string[] lst_eformid = eformid.Split(',');

                int proid = K2CoreLib.K2Utils.StartReProcess(SessionManager.UserDomain, assistantHRBP, lst_eformid[1], 
                    lst_eformid[0], ID, MailContent_HRBP, MailSubject_HRBP, MailHRBP, MailRequester, txtIDPhongBan.Text, 
                    txtIDBoPhan.Text, cboDepartment.Text, hdfBoPhanName.Value.Trim(), MailContent_Requestor, 
                    MailSubject_Requestor, MailRequestFor, MailRRM, MailGroupRRM.Trim(';'),version,cboNguoiYeuCau.SelectedValue
                    ,ApproveLink,ViewHistoryLink,ExpireDay,ExpireAlert);

                K2CoreLib.K2Utils.Update2EForm("0", lst_eformid[1], proid.ToString());

                //Insert ProcessID xuống data
                col_re.InsertProcessID(ID, lst_eformid[1]);
                
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        private void LoadFormForJobTitle()
        {
            try
            {
                if (cboChucvu.SelectedValue != "")
                {
                    RE_RequestCollection jDes = new RE_RequestCollection();
                    long bp = this.txtIDBoPhan.Text != "" ? long.Parse(this.txtIDBoPhan.Text) : 0;
                    long pb = this.txtIDPhongBan.Text != "" ? long.Parse(this.txtIDPhongBan.Text) : 0;
                    RE_RequestBL blRequest = jDes.GetByJobTitleID(int.Parse(cboChucvu.SelectedValue), bp, pb);

                    if (blRequest.DTO != null)
                    {
                        //Ẩn các nút gửi duyệt nếu record đang ở status=2 (Waiting)
                        if (blRequest.Status == 2 || blRequest.Status==3)
                        {
                            btnSave_Bot.Enabled = false;
                            btnSave_Top.Enabled = false;
                        }
                        else
                        {
                            btnSave_Bot.Enabled = true;
                            btnSave_Top.Enabled = true;
                        }
                        //

                        //***********Load thông tin request
                        this.hdfStatusRequest.Value = blRequest.Status.ToString();
                        //Nếu requestCode != "" --> Hiển thị link : Match CV, Task, PostJob
                        if (blRequest.RequestCode != null && blRequest.RequestCode != "" && this.hdfStatusRequest.Value != "6")
                        {
                            this.hplMatchCV_Top.Visible = true;
                            this.hplMatchCV_Top.NavigateUrl = string.Format(_MATCHSENDCV, blRequest.RequestCode);

                            this.hplMatchCV_Bot.Visible = true;
                            this.hplMatchCV_Bot.NavigateUrl = string.Format(_MATCHSENDCV, blRequest.RequestCode);

                            this.hplTask_Top.Visible = true;
                            this.hplTask_Top.NavigateUrl = string.Format(_TASK, blRequest.RequestID);
                            this.hplTask_Bot.Visible = true;
                            this.hplTask_Bot.NavigateUrl = string.Format(_TASK, blRequest.RequestID);

                            this.hplPost_Top.Visible = true;
                            this.hplPost_Top.NavigateUrl = string.Format(_POSTJOB, blRequest.RequestCode);

                            this.hplPost_Bot.Visible = true;
                            this.hplPost_Bot.NavigateUrl = string.Format(_POSTJOB, blRequest.RequestCode);
                        }

                        cboNguoiYeuCau.DataBind();
                        cboNguoiYeuCau.SelectedValue = blRequest.RequesterID;
                        txtRequester.Text = blRequest.RequesterID;
                        loadGeneralInfo(txtRequester.Text, false);

                        dtpRequestDate.SelectedDate = blRequest.RequestDate;
                        if (!blRequest.ExpectedDate.Equals(DateTime.Parse("1900-01-01")))
                            dtpExpectedDate.SelectedDate = blRequest.ExpectedDate;
                        txtGhiChuClose.Value = blRequest.NoteRequestClose;

                        //load jobTitle
                        //cboChucvu.DataBind();
                        //cboChucvu.SelectedValue = blRequest.LSJobTitleID.ToString();
                        SetComboValue(cboChucvu, dtsJobTitle, "prefix", blRequest.LSJobTitleID.ToString());
                        PopulateJobTitle(long.Parse(blRequest.LSJobTitleID.ToString()));

                        cboMoTa.DataBind();
                        cboMoTa.SelectedValue = blRequest.JobDescriptionID;
                        txtTenJob.Text = blRequest.JobDescriptionName;

                        //cboCapbac.DataBind();
                        //cboCapbac.SelectedValue = blRequest.JobLevel.ToString();

                        this.cboCapbac.DataBind();
                        dtsJobLevel.SelectParameters["p_strPrefix"].DefaultValue = "$SelectedValue$" + blRequest.LSJobTitleID.ToString();
                        SetComboValue(cboCapbac, blRequest.JobLevel.ToString(), true);


                        rdlLyDoTuyen.SelectedValue = blRequest.ReasonForRecruit.ToString();
                        cboReplaceFor.DataBind();
                        cboReplaceFor.SelectedValue = blRequest.ReplaceFor;
                        txtSoLuongTuyen.Text = blRequest.Quantity.ToString();


                        cboVanphonglamviec.DataBind();
                        cboVanphonglamviec.SelectedValue = blRequest.LSWorkingPlaceID.ToString();
                        rdlGender.SelectedValue = blRequest.Gender.ToString();
                        rdlJobType.SelectedValue = blRequest.JobType.ToString();
                        cboReportTo.DataBind();
                        cboReportTo.SelectedValue = blRequest.ReportTo;
                        //***********Load thông tin request                     


                        // Load thông tin Job Description     
                        txtTenJob.Text = blRequest.JobDescriptionName;
                        cboSoftSkill.DataBind();
                        cboProSkill.DataBind();
                        cboLanguageSkill.DataBind();

                        // Danh sách chuỗi ID Kỹ năng chuyên môn/ Kỹ năng mềm/Ngoai ngu             
                        if (blRequest.LSSoftSkillID != "")
                            LoadSkills(blRequest.LSSoftSkillID, cboSoftSkill);// Load kỹ năng mềm
                        if (blRequest.LSProSkillID != "")
                            LoadSkills(blRequest.LSProSkillID, cboProSkill);// Load kỹ năng chuyên môn        
                        if (blRequest.LSLanguageID != "")
                            LoadSkills(blRequest.LSLanguageID, cboLanguageSkill);// Load ngoại ngữ

                        this.cboTrinhDoHocVan.DataBind();
                        this.cboTrinhDoHocVan.SelectedValue = blRequest.LSProfessionalLevelID.ToString();

                        //Load cơ cấu chuyên môn            
                        RadTreeView treepro = (RadTreeView)cboProChart.Items[0].FindControl("trvProChart");
                        RadTreeView treemgt = (RadTreeView)cboMgtChart.Items[0].FindControl("trvMgtChart");
                        dtsProChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blRequest.ProSubGroupId.ToString();
                        treepro.DataBind();

                        //Lấy HIERACHI của cơ cấu chuyên môn/Cơ cấu quản lý
                        DataTable orgChartList = jDes.SelectOrgChartName(blRequest.RequestID);
                        if (orgChartList != null && orgChartList.Rows.Count > 0)
                        {
                            //Gán cây cơ cấu chuyên môn
                            string prochartname = orgChartList.Rows[0]["ProName"].ToString();
                            cboProChart.Items.Clear();
                            RadComboBoxItem item_prochart = new RadComboBoxItem(prochartname, orgChartList.Rows[0]["ProJobID"].ToString());
                            cboProChart.Items.Insert(0, item_prochart);
                            cboProChart.SelectedIndex = 0;
                            rttProChart_input.Text = prochartname;

                            //Load lại cây cơ cấu quản lý
                            dtsMgtChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blRequest.MgtSubGroupId.ToString();
                            treemgt.DataBind();

                            //Gán cây cơ cấu quản lý
                            string mgtchartname = orgChartList.Rows[0]["MgtName"].ToString();
                            cboMgtChart.Items.Clear();
                            RadComboBoxItem item_mgtchart = new RadComboBoxItem(mgtchartname, orgChartList.Rows[0]["MgtJobID"].ToString());
                            cboMgtChart.Items.Insert(0, item_mgtchart);
                            cboMgtChart.SelectedIndex = 0;
                            rttMgtChart_Input.Text = mgtchartname;
                        }

                        this.chkSuDung.Checked = blRequest.IsUse;
                        this.txtMoTaTiengViet.Content = blRequest.JobDescriptionVN;
                        this.txtMoTaTiengAnh.Content = blRequest.JobDescriptionEN;
                        this.txtYeuCauTiengViet.Content = blRequest.RequirementsVN;
                        this.txtYeuCauTiengAnh.Content = blRequest.RequirementsEN;
                        this.txtUuTienTiengViet.Content = blRequest.PreferableVN;
                        this.txtUuTienTiengAnh.Content = blRequest.PreferableEN;
                        // Load thông tin Job Description
                    }
                    else
                    {
                        btnSave_Bot.Enabled = true;
                        btnSave_Top.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }



        }
        private void LoadFormForUPdate()
        {

            try
            {
                RE_RequestCollection jDes = new RE_RequestCollection();
                RE_RequestBL blRequest = jDes.GetByID(this.hdfRequestID.Value);

                if (blRequest.DTO != null)
                {

                    //***********Load thông tin request
                    this.hdfStatusRequest.Value = blRequest.Status.ToString();

                    // 2 trang thai 3:Opening/2:Waiting thi RR/RRM va co quyen sua thong tin 
                    //ne
                    if (((this.hdfStatusRequest.Value == "2" || this.hdfStatusRequest.Value == "3") && (this.hdfRole.Value == "RR" || this.hdfRole.Value == "RRM"))
                        || this.hdfStatusRequest.Value == "1" || this.hdfStatusRequest.Value == "5" // Save/Reject duoc Edit                       
                       )
                    {
                        this.btnSave_Bot.Enabled = true;
                        this.btnSave_Top.Enabled = true;
                    }
                    else
                    {
                        this.btnSave_Bot.Enabled = false;
                        this.btnSave_Top.Enabled = false;
                    }

                    //Nếu requestCode != "" --> Hiển thị link : Match CV, Task, PostJob
                    if (blRequest.RequestCode != null && blRequest.RequestCode != "" && this.hdfStatusRequest.Value != "6")
                    {
                        this.hplMatchCV_Top.Visible = true;
                        this.hplMatchCV_Top.NavigateUrl = string.Format(_MATCHSENDCV, blRequest.RequestID);

                        this.hplMatchCV_Bot.Visible = true;
                        this.hplMatchCV_Bot.NavigateUrl = string.Format(_MATCHSENDCV, blRequest.RequestID);

                        this.hplTask_Top.Visible = true;
                        this.hplTask_Top.NavigateUrl = string.Format(_TASK, blRequest.RequestID);
                        this.hplTask_Bot.Visible = true;
                        this.hplTask_Bot.NavigateUrl = string.Format(_TASK, blRequest.RequestID);

                        this.hplPost_Top.Visible = true;
                        this.hplPost_Top.NavigateUrl = string.Format(_POSTJOB, blRequest.RequestID);

                        this.hplPost_Bot.Visible = true;
                        this.hplPost_Bot.NavigateUrl = string.Format(_POSTJOB, blRequest.RequestID);
                    }

                    cboNguoiYeuCau.DataBind();
                    cboNguoiYeuCau.SelectedValue = blRequest.RequesterID;
                    txtRequester.Text = blRequest.RequesterID;
                    // Load thong tinnguoi yeu cau
                    loadGeneralInfo(blRequest.RequesterID, false);

                    dtpRequestDate.SelectedDate = blRequest.RequestDate;
                    if (!blRequest.ExpectedDate.Equals(DateTime.Parse("1900-01-01")))
                        dtpExpectedDate.SelectedDate = blRequest.ExpectedDate;
                    txtGhiChuClose.Value = blRequest.NoteRequestClose;

                    //load jobTitle
                    //cboChucvu.DataBind();
                    //cboChucvu.SelectedValue = blRequest.LSJobTitleID.ToString();
                    SetComboValue(cboChucvu, dtsJobTitle, "prefix", blRequest.LSJobTitleID.ToString());
                    PopulateJobTitle(long.Parse(blRequest.LSJobTitleID.ToString()));

                    cboMoTa.DataBind();
                    cboMoTa.SelectedValue = blRequest.JobDescriptionID;
                    txtTenJob.Text = blRequest.JobDescriptionName;

                    //cboCapbac.DataBind();
                    //cboCapbac.SelectedValue = blRequest.JobLevel.ToString();

                    this.cboCapbac.DataBind();
                    dtsJobLevel.SelectParameters["p_strPrefix"].DefaultValue = "$SelectedValue$" + blRequest.LSJobTitleID.ToString();
                    SetComboValue(cboCapbac, blRequest.JobLevel.ToString(), true);


                    rdlLyDoTuyen.SelectedValue = blRequest.ReasonForRecruit.ToString();
                    cboReplaceFor.DataBind();
                    cboReplaceFor.SelectedValue = blRequest.ReplaceFor;
                    txtSoLuongTuyen.Text = blRequest.Quantity.ToString();


                    cboVanphonglamviec.DataBind();
                    cboVanphonglamviec.SelectedValue = blRequest.LSWorkingPlaceID.ToString();
                    rdlGender.SelectedValue = blRequest.Gender.ToString();
                    rdlJobType.SelectedValue = blRequest.JobType.ToString();
                    cboReportTo.DataBind();
                    cboReportTo.SelectedValue = blRequest.ReportTo;
                    //***********Load thông tin request                     


                    // Load thông tin Job Description     
                    txtTenJob.Text = blRequest.JobDescriptionName;
                    cboSoftSkill.DataBind();
                    cboProSkill.DataBind();
                    cboLanguageSkill.DataBind();

                    // Danh sách chuỗi ID Kỹ năng chuyên môn/ Kỹ năng mềm/Ngoai ngu             
                    if (blRequest.LSSoftSkillID != "")
                        LoadSkills(blRequest.LSSoftSkillID, cboSoftSkill);// Load kỹ năng mềm
                    if (blRequest.LSProSkillID != "")
                        LoadSkills(blRequest.LSProSkillID, cboProSkill);// Load kỹ năng chuyên môn        
                    if (blRequest.LSLanguageID != "")
                        LoadSkills(blRequest.LSLanguageID, cboLanguageSkill);// Load ngoại ngữ


                    this.cboTrinhDoHocVan.DataBind();
                    this.cboTrinhDoHocVan.SelectedValue = blRequest.LSProfessionalLevelID.ToString();


                    //Load cơ cấu chuyên môn            
                    RadTreeView treepro = (RadTreeView)cboProChart.Items[0].FindControl("trvProChart");
                    RadTreeView treemgt = (RadTreeView)cboMgtChart.Items[0].FindControl("trvMgtChart");
                    dtsProChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blRequest.ProSubGroupId.ToString();
                    treepro.DataBind();

                    //Lấy HIERACHI của cơ cấu chuyên môn/Cơ cấu quản lý
                    DataTable orgChartList = jDes.SelectOrgChartName(blRequest.RequestID);
                    if (orgChartList != null && orgChartList.Rows.Count > 0)
                    {
                        //Gán cây cơ cấu chuyên môn
                        string prochartname = orgChartList.Rows[0]["ProName"].ToString();
                        cboProChart.Items.Clear();
                        RadComboBoxItem item_prochart = new RadComboBoxItem(prochartname, orgChartList.Rows[0]["ProJobID"].ToString());
                        cboProChart.Items.Insert(0, item_prochart);
                        cboProChart.SelectedIndex = 0;
                        rttProChart_input.Text = prochartname;

                        //Load lại cây cơ cấu quản lý
                        dtsMgtChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blRequest.MgtSubGroupId.ToString();
                        treemgt.DataBind();

                        //Gán cây cơ cấu quản lý
                        string mgtchartname = orgChartList.Rows[0]["MgtName"].ToString();
                        cboMgtChart.Items.Clear();
                        RadComboBoxItem item_mgtchart = new RadComboBoxItem(mgtchartname, orgChartList.Rows[0]["MgtJobID"].ToString());
                        cboMgtChart.Items.Insert(0, item_mgtchart);
                        cboMgtChart.SelectedIndex = 0;
                        rttMgtChart_Input.Text = mgtchartname;
                    }

                    this.chkSuDung.Checked = blRequest.IsUse;
                    this.txtMoTaTiengViet.Content = blRequest.JobDescriptionVN;
                    this.txtMoTaTiengAnh.Content = blRequest.JobDescriptionEN;
                    this.txtYeuCauTiengViet.Content = blRequest.RequirementsVN;
                    this.txtYeuCauTiengAnh.Content = blRequest.RequirementsEN;
                    this.txtUuTienTiengViet.Content = blRequest.PreferableVN;
                    this.txtUuTienTiengAnh.Content = blRequest.PreferableEN;
                    // Load thông tin Job Description
                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }



        }
        private void LoadJobDescriptionByID(string JobDesID)
        {
            RE_JobDescriptionCollection collection = new RE_JobDescriptionCollection();
            RE_JobDescriptionBL blJob = collection.FindByID(JobDesID);

            try
            {
                if (blJob.DTO != null)
                {
                    RadTreeView treepro = (RadTreeView)cboProChart.Items[0].FindControl("trvProChart");
                    RadTreeView treemgt = (RadTreeView)cboMgtChart.Items[0].FindControl("trvMgtChart");
                    txtTenJob.Text = blJob.JobDescriptionName;
                    cboCapbac.SelectedValue = blJob.JobLevel.ToString();
                    // Danh sách chuỗi ID Kỹ năng chuyên môn/ Kỹ năng mềm/Ngoai ngu

                    DataTable skillList = collection.getSkillList(blJob.JobDescriptionID);
                    if (skillList != null & skillList.Rows.Count > 0)
                    {
                        if (skillList.Rows[0]["LSSoftSkillID"] != null)
                            LoadSkills(skillList.Rows[0]["LSSoftSkillID"].ToString(), cboSoftSkill);// Load kỹ năng mềm                            
                        if (skillList.Rows[0]["LSProSkillID"] != null)
                            LoadSkills(skillList.Rows[0]["LSProSkillID"].ToString(), cboProSkill);// Load kỹ năng chuyên môn

                    }
                    if (skillList != null & skillList.Rows.Count > 1)
                    {
                        if (skillList.Rows[1]["LSLanguageID"] != null)
                            LoadSkills(skillList.Rows[1]["LSLanguageID"].ToString(), cboLanguageSkill);// Load ngoại ngữ
                    }


                    this.cboTrinhDoHocVan.SelectedValue = blJob.LSProfessionalLevelID.ToString();


                    //Load cơ cấu chuyên môn             
                    dtsProChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blJob.ProSubGroupId.ToString();
                    treepro.DataBind();

                    //Lấy HIERACHI của cơ cấu chuyên môn/Cơ cấu quản lý
                    DataTable orgChartList = collection.SelectOrgChartName(blJob.JobDescriptionID);
                    //Gán cây cơ cấu chuyên môn
                    string prochartname = orgChartList.Rows[0]["ProName"].ToString();
                    cboProChart.Items.Clear();
                    RadComboBoxItem item_prochart = new RadComboBoxItem(prochartname, orgChartList.Rows[0]["ProJobID"].ToString());
                    cboProChart.Items.Insert(0, item_prochart);
                    cboProChart.SelectedIndex = 0;
                    rttProChart_input.Text = prochartname;

                    //Load lại cây cơ cấu quản lý
                    dtsMgtChart.SelectParameters["prefix"].DefaultValue = "$SelectedValue$" + blJob.MgtSubGroupId.ToString();
                    treemgt.DataBind();

                    //Gán cây cơ cấu quản lý
                    string mgtchartname = orgChartList.Rows[0]["MgtName"].ToString();
                    cboMgtChart.Items.Clear();
                    RadComboBoxItem item_mgtchart = new RadComboBoxItem(mgtchartname, orgChartList.Rows[0]["MgtJobID"].ToString());
                    cboMgtChart.Items.Insert(0, item_mgtchart);
                    cboMgtChart.SelectedIndex = 0;
                    rttMgtChart_Input.Text = mgtchartname;

                    this.chkSuDung.Checked = blJob.IsUse;
                    this.txtMoTaTiengViet.Content = blJob.JobDescriptionVN;
                    this.txtMoTaTiengAnh.Content = blJob.JobDescriptionEN;
                    this.txtYeuCauTiengViet.Content = blJob.RequirementsVN;
                    this.txtYeuCauTiengAnh.Content = blJob.RequirementsEN;
                    this.txtUuTienTiengViet.Content = blJob.PreferableVN;
                    this.txtUuTienTiengAnh.Content = blJob.PreferableEN;
                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }

        }
        public void LoadSkills(string selectedItems, RadComboBox c)
        {
            try
            {
                if (selectedItems != null && selectedItems != "")
                {
                    string[] str_list = selectedItems.Split(';');
                    foreach (string s in str_list)
                    {

                        if (s != "")
                        {
                            c.SelectedValue = s.ToString();
                            RadComboBoxItem item = c.SelectedItem;
                            CheckBox chk = null;
                            if (item != null)
                            {
                                if (c.ID == "cboSoftSkill")
                                    chk = (CheckBox)item.FindControl("chkSoftSkill");
                                else if (c.ID == "cboProSkill")
                                    chk = (CheckBox)item.FindControl("chkProSkill");
                                else if (c.ID == "cboLanguageSkill")
                                    chk = (CheckBox)item.FindControl("chkLanguageSkill");
                                if (chk != null)
                                    chk.Checked = true;
                            }
                        }
                    }

                    SetComboValue(c, c.ID, true);
                }
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        /// <summary>
        /// Load thong tin chung
        /// </summary>
        /// <param name="userName"></param>: username handle request 
        /// <param name="chkShowCombo"></param>:true: kiem tra truong hop show Combobox request
        private void loadGeneralInfo(string userName, bool chkShowCombo)
        {
            RE_RequestCollection jDes = new RE_RequestCollection();
            DataTable table = jDes.GetGeneralInfo(userName);
            int isRRGroup = 0;

            dtsDepartment.SelectParameters["UserName"].DefaultValue = userName;
            cboDepartment.DataSourceID = dtsDepartment.ID;
            cboDepartment.DataBind();

            if (table.Rows.Count > 0)
            {
                try
                {
                    CultureInfo provider = CultureInfo.InvariantCulture;
                    string format = "dd/MM/yyyy";
                    //table.Rows[0][0]!=null?table.Rows[0][0].ToString();
                    txtRequester.Text = table.Rows[0]["Requester"].ToString();
                    txtRequesterRole.Text =table.Rows[0]["JobTitleName"].ToString();
                    hdfIDRequesterRole.Value = table.Rows[0]["JobTitleID"].ToString();
                    txtBoPhan.Text = table.Rows[0]["AreaName"].ToString();
                    txtPhongBan.Text = table.Rows[0]["DepartmentName"].ToString();
                    hdfBoPhanName.Value = table.Rows[0]["AreaName"].ToString();
                    hdfPhongBanName.Value = table.Rows[0]["DepartmentName"].ToString();
                    this.txtIDBoPhan.Text = table.Rows[0]["AreaID"].ToString();
                    this.txtIDPhongBan.Text = table.Rows[0]["DepartmentID"].ToString();
                    this.txtIDCongTy.Text = table.Rows[0]["CompanyID"].ToString();
                    dtpRequestDate.SelectedDate =DateTime.ParseExact(table.Rows[0]["RequestDate"].ToString(),format,provider);
                    isRRGroup = int.Parse(table.Rows[0]["IsRRGroup"].ToString());
                    this.hdfRole.Value = table.Rows[0]["Role"].ToString();
                    this.hdfJobFamily.Value = table.Rows[0]["JobFamily"].ToString();
                    this.hdfJobGroup.Value = table.Rows[0]["JobGroup"].ToString();
                    hdfRequestForName.Value = table.Rows[0]["RequesterName"].ToString();

                    //Load lai thong tin department
                    SetComboValue(cboDepartment, table.Rows[0]["DepartmentID"].ToString(), true);

                    if (chkShowCombo)
                    {
                        if (isRRGroup == 1)// role HRBP, RR, RRM --> Hiển thị combobox chọn requester giúp
                        {
                            this.divRequestor.Style.Add("display", "");
                        }
                        else
                        {
                            this.divRequestor.Style.Add("display", "none");
                        }
                    }
                }
                catch (Exception ex)
                {
                    AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                    MessageBox.Show(message);
                }
            }
        }
        /// <summary>
        /// Parse chuỗi cách nhau bởi dấu ";" thành mảng
        /// </summary>
        /// <param name="listid"></param>
        /// <returns></returns>
        public List<Int64> ParseItem(string listid)
        {
            List<Int64> result = new List<Int64>();
            try
            {
                string[] str_listid = listid.Split(';');
                foreach (string id in str_listid)
                {
                    if (!string.IsNullOrEmpty(id))
                    {
                        result.Add(Convert.ToInt64(id));
                    }
                }
            }
            catch (Exception ex)
            {
                DataAccessExceptionHandler.HandleException(ex);
            }
            return result;
        }
        public RE_RequestBL addDataToObject()
        {
            RE_RequestBL jDes = new RE_RequestBL();

            try
            {
                //** THÔNG TIN REQUEST
                jDes.RequestID = this.hdfRequestID.Value;
                jDes.RequesterRole = hdfIDRequesterRole.Value != "" ? long.Parse(hdfIDRequesterRole.Value.ToString()) : 0;


                jDes.RequesterID = txtRequester.Text;
                jDes.LSDivisionID = txtIDBoPhan.Text != "" ? long.Parse(txtIDBoPhan.Text.ToString()) : 0;
                jDes.LSDepartmentID = txtIDPhongBan.Text != "" ? long.Parse(txtIDPhongBan.Text.ToString()) : 0;
                jDes.LSCompanyID = txtIDCongTy.Text != "" ? long.Parse(txtIDCongTy.Text.ToString()) : 0;

                jDes.RequestDate = DateTime.Parse(dtpRequestDate.SelectedDate.ToString());
                jDes.ExpectedDate = dtpExpectedDate.SelectedDate != null ? DateTime.Parse(dtpExpectedDate.SelectedDate.ToString()) : DateTime.Parse("1900-01-01");
                jDes.NoteRequestClose = txtGhiChuClose.Value;
                jDes.LSJobTitleID = long.Parse(cboChucvu.SelectedValue);
                jDes.ReasonForRecruit = ushort.Parse(rdlLyDoTuyen.SelectedValue);
                if (rdlLyDoTuyen.SelectedValue != "1")
                    jDes.ReplaceFor = cboReplaceFor.SelectedValue;
                jDes.LSWorkingPlaceID = cboVanphonglamviec.SelectedValue != "" ? long.Parse(cboVanphonglamviec.SelectedValue) : 0;
                jDes.Gender = ushort.Parse(rdlGender.SelectedValue);
                jDes.JobType = ushort.Parse(rdlJobType.SelectedValue);
                jDes.ReportTo = cboReportTo.SelectedValue;
                jDes.Quantity = int.Parse(txtSoLuongTuyen.Text);
                // Thông tin kỹ năng chuyên môn/mềm/ngoại ngữ
                jDes.LSProSkillID = cboProSkill.SelectedValue;
                jDes.LSSoftSkillID = cboSoftSkill.SelectedValue;
                jDes.LSLanguageID = cboLanguageSkill.SelectedValue;
                //** THÔNG TIN REQUEST

                //** THÔNG TIN JOBDESCRIPTION
                jDes.JobDescriptionCode = cboMoTa.Text; // JD Code
                jDes.JobDescriptionID = cboMoTa.SelectedValue; // JD ID
                jDes.JobDescriptionName = txtTenJob.Text;

                jDes.JobLevel = long.Parse(cboCapbac.SelectedValue);
                jDes.LSJobTitleID = long.Parse(cboChucvu.SelectedValue);
                if (cboTrinhDoHocVan.SelectedValue != "")
                    jDes.LSProfessionalLevelID = long.Parse(cboTrinhDoHocVan.SelectedValue); // Trinh độ học vấn

                // Luu co cau chuyen mon
                //Projob
                List<Int64> Projob = ParseItem(cboProChart.SelectedValue);

                if (Projob.Count > 0)
                    jDes.ProJobFamilyId = Projob[0];
                if (Projob.Count > 1)
                    jDes.ProJobGroupId = Projob[1];
                if (Projob.Count > 2)
                    jDes.ProSubGroupId = Projob[2];

                //MgtJob
                List<Int64> MgtJob = ParseItem(cboMgtChart.SelectedValue);
                if (MgtJob.Count > 0)
                    jDes.MgtJobFamilyId = MgtJob[0];
                if (MgtJob.Count > 1)
                    jDes.MgtJobGroupId = MgtJob[1];
                if (MgtJob.Count > 2)
                    jDes.MgtSubGroupId = MgtJob[2];


                jDes.IsUse = chkSuDung.Checked;
                jDes.JobDescriptionVN = txtMoTaTiengViet.Content;
                jDes.JobDescriptionEN = txtMoTaTiengAnh.Content;
                jDes.RequirementsVN = txtYeuCauTiengViet.Content;
                jDes.RequirementsEN = txtYeuCauTiengAnh.Content;
                jDes.PreferableVN = txtUuTienTiengViet.Content;
                jDes.PreferableEN = txtUuTienTiengAnh.Content;
                jDes.LSPositionClassApply = Convert.ToInt64(string.IsNullOrEmpty(cboPCApply.SelectedValue) ? "0" : cboPCApply.SelectedValue);
                jDes.LSPositionClassStandard = hdfPCStandard.Value;
                //** THÔNG TIN JOBDESCRIPTION
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
            return jDes;

        }

        /// <summary>        
        /// Get combo Prochart và MgtChar theo jobtitle
        /// </summary>
        /// <param name="jobtitle">mã jobtitle</param>        
        public void PopulateJobTitle(long jobtitle)
        {
            try
            {
                #region Set Pro Chart
                cboProChart.Items.Clear();
                cboProChart.Items.Insert(0, new RadComboBoxItem("", ""));
                cboProChart.SelectedIndex = 0;

                //Kiểm tra nếu tồn tại 1 mapping giữa Jobtitle và Subgroup thì gán cấy prochart vào combo
                HR_WorkingRecordCollection cl = new HR_WorkingRecordCollection();
                long subgroupid = cl.CheckJobTitle_SubGroup(jobtitle);
                if (subgroupid > 0)
                {
                    string prochartname = cl.GetProChartName(subgroupid);
                    string prochartid = cl.GetProChartID(subgroupid);

                    cboProChart.Items.Clear();
                    cboProChart.Items.Insert(0, new RadComboBoxItem(prochartname, prochartid));
                    cboProChart.SelectedIndex = 0;

                    rttProChart_input.Text = prochartname;
                    lblCanhBaoProChart.Visible = false;
                }
                else
                    lblCanhBaoProChart.Visible = true;
                //
                #endregion

                dtsMgtChart.SelectParameters["Jobtitle"].DefaultValue = jobtitle.ToString();
                RadTreeView treeviewmgt = (RadTreeView)cboMgtChart.Items[0].FindControl("trvMgtChart");
                treeviewmgt.DataBind();

                dtsJobLevel.SelectParameters["jobtitle"].DefaultValue = jobtitle.ToString();
                dtsJobLevel.SelectParameters["p_strPrefix"].DefaultValue = "";
                cboCapbac.DataSourceID = dtsJobLevel.ID;
                cboCapbac.DataBind();
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }

        public void SetComboPC()
        {
            try
            {
                //Gán thông tin PC
                string value = "";
                string text = "";
                foreach (RadComboBoxItem item in cboPCStandard.Items)
                {
                    CheckBox chk = (CheckBox)item.FindControl("chkPC");
                    chk.Checked = true;
                    value += ";" + item.Value;
                    text += ";" + item.Text;
                }

                cboPCStandard.Items.Insert(cboPCStandard.Items.Count, new RadComboBoxItem(text.Trim(';'), value.Trim(';')));
                cboPCStandard.SelectedIndex = cboPCStandard.Items.Count - 1;
                cboPCStandard.Items[cboPCStandard.Items.Count - 1].Visible = false;

                hdfPCStandard.Value = value.Trim(';');
            }
            catch (Exception ex)
            {
                AlertMessage message = UserInterfaceExceptionHandler.HandleExcetion(ex);
                MessageBox.Show(message);
            }
        }
        #endregion
    }
}